package com.pets.springboot_petshop.mapper;

import com.pets.springboot_petshop.entity.User;
import com.pets.springboot_petshop.entity.Userpet;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: wxk
 * @Email: 2089967794@qq.com
 * @Date: 2024/10/12 下午4:30 周六
 * @Description: 用户宠物访问层接口
 */
@Mapper
@Repository
public interface UserpetMapper {
    //id查询
    @Select("select a.id , a.name,a.user_id, b.username ,a.pettype_id,c.name as pettype_name , a.gender,a.age,a.remark,a.petsize,a.img,a.create_time" +
            " from userpet a LEFT JOIN user b on a.user_id = b.id LEFT JOIN pettype c on a.pettype_id = c.id where a.id = #{id};")
    Userpet selectUserpetid(int id);
    //用户id查询
    @Select("select a.id , a.name,a.user_id, b.username ,a.pettype_id,c.name as pettype_name , a.gender,a.age,a.remark,a.petsize,a.img,a.create_time" +
            " from userpet a LEFT JOIN user b on a.user_id = b.id LEFT JOIN pettype c on a.pettype_id = c.id where a.user_id = #{user_id};")
    List<Userpet> selectUserpetUserid(int user_id);
    //查询所有
    @Select("select a.id , a.name,a.user_id, b.username ,a.pettype_id,c.name as pettype_name , a.gender,a.age,a.remark,a.petsize,a.img,a.create_time" +
            " from userpet a LEFT JOIN user b on a.user_id = b.id LEFT JOIN pettype c on a.pettype_id = c.id;")
    List<Userpet> findAll();
    //添加
    @Insert("insert into userpet(name,user_id,gender,age,remark,pettype_id,petsize,img,create_time,update_time)values" +
            "(#{name},#{user_id},#{gender},#{age},#{remark},#{pettype_id},#{petsize},#{img},now(),now());")
    int addUserpet(Userpet userpet);
    //删除
    @Delete("delete from userpet where id=#{id};")
    int deleteUserpetById(int id);
    //修改数据
    @Update("UPDATE userpet SET name=#{name},pettype_id=#{pettype_id}, petsize=#{petsize},img=#{img},gender=#{gender},age=#{age},remark=#{remark},update_time=now() where id= #{id};")
    int updateUserpetById(Userpet userpet);
    //修改用户头像
    @Update("UPDATE userpet SET img=#{img},update_time=now() WHERE id = #{id} ;")
    int updateimg(Userpet userpet);
}
